package responsibility;


public abstract class Handler {
    public Handler nextHandler;

    public void handleRequest(AbstractRequest request) {
        if (getHandleLevel() == request.getRequestLevel()) {
            handle(request);
        } else {
            if (nextHandler != null) {
                nextHandler.handleRequest(request);
            } else {
                System.out.println("无法匹配，所有消息处理对象都无法处理");
            }
        }
    }

    public abstract void handle(AbstractRequest abstractRequest);

    public abstract int getHandleLevel();
}
